
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <semaphore.h>
#include "hfile.h"

#define ACC_RIGHT 600
#define FILEPATH "/tmp/commchan.bin"
#define NUMINTS  (1000)
#define FILESIZE (NUMINTS * sizeof(int))

/*
 *This function will send data to the FSP for IPC, not data transmission
 */

int askFsp(char *Buffer)
{
    int fd;
    int bytesWritten = 0;
    char *map;  /* mmapped array of chars(array of chars) */
    printf("schrijftest1\n");
    //Open bin file for mmap with read write rights
    fd = open(FILEPATH, O_RDWR);
    if (fd == -1)
    {
	perror("Error opening file for reading");
	exit(EXIT_FAILURE);
    }
    printf("schrijftest2\n");
    bytesWritten = write(fd, Buffer, strlen(Buffer));//write to mmf
    printf("schrijftest3, written: %d\n", bytesWritten);

    map = (char*)mmap(0, FILESIZE,  PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
	close(fd);
	perror("Error mmapping the file");
	exit(EXIT_FAILURE);
    }
    printf("MAP geschreven\n");
    printf("inhoud: %s\n", map);

    return 0;
}

